/*
 * Visualization of gradient information.
 *
 */

#include <vtkImageCast.h>
#include <vtkImageConstantPad.h>
#include <vtkImageEuclideanToPolar.h>
#include <vtkImageExtractComponents.h>
#include <vtkImageGaussianSmooth.h>
#include <vtkImageGradient.h>
#include <vtkImageHSVToRGB.h>
#include <vtkImageMagnify.h>
#include <vtkImageViewer.h>
#include <vtkMetaImageReader.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>

#include <iomanip>
#include <iostream>
#include <string>

#include <vtkJPEGReader.h>
#include <vtkImageViewer2.h>

#include <vtkImageActor.h>


int main(int argc, char* argv[])
{
    // Create the RenderWindowInteractor.
    vtkNew<vtkRenderWindowInteractor> iren;
    vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
    vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->AddRenderer(renderer);
    iren->SetRenderWindow(renderWindow);



    vtkNew<vtkJPEGReader> JPEGReader;
    JPEGReader->SetFileName("/Users/dai/Work/vtk/VTK-Example/AMy/ImageEuclideanToPolar/0.jpg");

    // Convert the data to polar coordinates.
    // The image magnitude is mapped into saturation value,
    //  whilst the gradient direction is mapped into hue value.
    vtkNew<vtkImageEuclideanToPolar> polar;
    polar->SetInputConnection(JPEGReader->GetOutputPort());
//    polar->SetThetaMaximum(255.0);

    vtkNew<vtkImageViewer2> viewer;
    viewer->SetInputConnection(polar->GetOutputPort());
    viewer->GetRenderWindow()->SetWindowName("ImageGradient");

    viewer->SetupInteractor(iren);
    viewer->Render();



//    // Set up a viewer for the image.
//    // Note that vtkImageViewer and vtkImageViewer2 are convenience wrappers
//    // around
//    // vtkActor2D, vtkImageMapper, vtkRenderer, and vtkRenderWindow.
//    // So all that needs to be supplied is the interactor.
//    vtkNew<vtkImageViewer> viewer;
//    viewer->SetInputConnection(rgb->GetOutputPort());
//    viewer->SetZSlice(22);
//    viewer->SetColorWindow(255.0);
//    viewer->SetColorLevel(127.0);
//    viewer->GetRenderWindow()->SetSize(512, 512);
//    viewer->GetRenderer()->SetBackground(colors->GetColor3d("Silver").GetData());
//    viewer->GetRenderWindow()->SetWindowName("ImageGradient");


    renderWindow->Render();
    iren->Initialize();
    iren->Start();

    return EXIT_SUCCESS;
}